﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Audio;
//using Microsoft.Xna.Framework.Content;
//using Microsoft.Xna.Framework.GamerServices;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
//using Microsoft.Xna.Framework.Media;
//using Microsoft.Xna.Framework.Net;
//using Microsoft.Xna.Framework.Storage;

namespace WindowsGame3
{
    public class block2
    {
      
 
       public Vector2[] BuldingNextPiece(int y, int x, int movehorizontal)

        {
            int[,] shapeL = { 
                                 
                                 {0, 0, 0, 0, 0},  
                                 {0, 0, 1, 0, 0},  
                                 {0, 0, 2, 0, 0},  
                                 {0, 0, 1, 1, 0},  
                                 {0, 0, 0, 0, 0}
                                 
                                 };
           int[,] ShapeofPiece = shapeL;

          return positionRectangle(ShapeofPiece, x, y, movehorizontal); //call PositionRectangle method automaticly to add it to the play area
           //Return Vector2[] containing vector2ArrayOfRectangleCoordsToDrawPiece's for all blocks to be drawn
        
        }


        
        public Vector2[] positionRectangle(int[,] Shape, int x, int y, int movehorizontal)
        {
           // x += movehorizontal;

            //*set reset x ammount to initial value of .
            int resetXammountTogame1X = x + movehorizontal; 
           // int x = truex;
           
            int countArrayDimension = 0;
            
            Vector2[] vector2ArrayOfRectangleCoordsToDrawPiece; //array to dump piece coordinates into it.
            vector2ArrayOfRectangleCoordsToDrawPiece = new Vector2[4]; //4 rectangles per each tetris piece


            int scale = Game1.scale; //find a better way of doing this rather than making scale public.
            int vector2ArrayOfRectangleCoordsToDrawPiecedimension = 0; //this holds the dimension of the array we are itereating thorugh

            foreach (int element in Shape) 
            {
                // Y is how much to move down after each array dimension is exceeded. We used the height of the rectangle
                if (countArrayDimension % 5 == 0) //every 5th dimension execute IF
                {                    
                    y += Game1.heightOfRectangleToBeDrawn;        // ycoordinate + rectangle height to set the next lin       
                    x = resetXammountTogame1X; //needed to pass the real value of x origin back to X.
                }

                if (element >= 1)
                {
                    x += Game1.widthOfRectangleToBeDrawn;
                    vector2ArrayOfRectangleCoordsToDrawPiece[vector2ArrayOfRectangleCoordsToDrawPiecedimension].X = x;
                    vector2ArrayOfRectangleCoordsToDrawPiece[vector2ArrayOfRectangleCoordsToDrawPiecedimension].Y = y;
                    vector2ArrayOfRectangleCoordsToDrawPiecedimension++;
                }
                
              countArrayDimension += 1;
               }
            return vector2ArrayOfRectangleCoordsToDrawPiece;
        }
    }
}

